<?php
	namespace Admin\Model;

	class UserModel extends \Think\Model
	{	
		// 遍历获取用户表信息
		public function getAll()
		{
			//这里获取所有的数据
			$userlist=$this->select();

			
			// foreach ($userlist as $ke => $va) 
			// {	
			// 	$userlist[$ke]['sex']=$va['sex']?'男':'女';
			// 	$userlist[$ke]['status']=$va['status']?'显示':'禁用';
			// }
			
			return $userlist;
		}


		//查询条件的拼接
		public function getFind($data)
		{
			//处理data
			foreach ($data as $key => $value) {
			 	$where.="`$key`='$value' AND ";
			}
			 $where=trim($where,' AND ');
			 $res=$this->where($where)->find();
			 if (!is_null($res)) {
			 	return $res;
			 }else{
			 	return false;
			 }
		}

		//用户状态跳转 (没用上)
		public function UpStatus($id){
			//获取表但信息
			$list=$this->field('status')->where('id='.$id)->select();
			// var_dump($list);
			if ($list[0]['status']==1) 
			{
				$res=$this->where('id='.$id)->save(['status'=>0]);
				// $this->error('更改成功');
			}else{
				$res=$this->where('id='.$id)->save(['status'=>1]);
				// $this->error('更改成功');
			}
		}

		//删除用户
		public function del($id){

			$li = $this->where('id='.$id)->delete($id);
			if ($li) {
				return true;
			}
		}


		//重置密码
		public function resets($id){
			$data['poss'] = md5('123456');
			$res=$this->where('id='.$id)->data($data)->save();
			return $res;
		}
		
	}